package model

import (
	"database/sql"
	"time"
)

type ResCommon struct {
	Id         int64     `json:"id"`
	CreateDate time.Time `gorm:"autoCreateTime" json:"create_date"`
	WriteDate  time.Time `gorm:"autoUpdateTime" json:"write_date"`
	CreateUid  int64     `json:"create_uid"`
	WriteUid   int64     `json:"write_uid"`
	CreateUser *ResUsers `gorm:"foreignKey:Id;references:CreateUid"`
	WriterUser *ResUsers `gorm:"foreignKey:Id;references:WriteUid"`
}
type ResUsers struct {
	ResCommon
	CID              string         `json:"cid" gorm:"column:cid;"`
	Login            string         `json:"login"`
	LoginMobile      sql.NullString `json:"login_mobile"`
	Password         string         `json:"password"`
	CompanyId        int64          `json:"company_id" gorm:"default:1"`
	PartnerId        int64          `json:"partner_id"`
	NotificationType string         `json:"notification_type" gorm:"default:inbox"`
	Signature        string         `json:"signature"`
	Active           bool           `json:"active" gorm:"default:true"`
	Share            bool           `json:"share" gorm:"default:false"`
	IsBackstage      bool           `json:"is_backstage" gorm:"default:false"`
	DynamicPassword  string         `json:"dynamic_password"`
	//IsVip                   bool           `json:"is_vip"`
	//IsStudy                 bool           `json:"is_study"`
	DynamicPasswordDatetime time.Time    `json:"dynamic_password_datetime"`
	CompanyIds              []ResCompany `json:"company_ids" gorm:"many2many:res_company_users_rel;"`
	Partner                 ResPartner
	Company                 ResCompany
	DepartmentId            sql.NullInt64 `json:"department_id"`
	Department              HrDepartment
	RegistrationId          sql.NullString
}
type ResUsersLog struct {
	ResCommon
}
type ResPartner struct {
	ResCommon
	Name                   string        `json:"name"`
	CID                    string        `json:"cid" gorm:"column:cid"`
	Date                   sql.NullTime  `json:"date"`
	Sex                    string        `json:"sex"`
	Title                  sql.NullInt64 `json:"title"`
	ContactAddressComplete string
	IndustryId             int64 `json:"industry_id"`
	Industry               UtmIndustry
	Abb                    string         `json:"abb"`
	CompanyId              int64          `json:"company_id" gorm:"default:1"`
	DisplayName            string         `json:"display_name"`
	Lang                   sql.NullString `json:"lang" gorm:"default:zh_CN"`
	Tz                     sql.NullString `json:"tz" gorm:"default:Asia/Shanghai"`
	Active                 bool           `json:"active" gorm:"default:true"`
	Type                   string         `json:"type"`
	CityName               string         `json:"city" gorm:"column:city"`
	Street                 sql.NullString `json:"street"`
	Street2                sql.NullString `json:"street2"`
	CountryId              sql.NullInt64  `json:"country_id" gorm:"default:48"`
	StateId                sql.NullInt64  `json:"state_id"`
	CityId                 sql.NullInt64  `json:"city_id"`
	Zip                    sql.NullString `json:"zip"`
	AreaId                 sql.NullInt64  `json:"area_id"`
	UserId                 int64          `json:"user_id"`
	Email                  sql.NullString `json:"email"`
	EmailNormalized        sql.NullString `json:"email_normalized"`
	Phone                  sql.NullString `json:"phone"`
	Mobile                 sql.NullString `json:"mobile"`
	IsCompany              bool           `json:"is_company"`
	Color                  int16          `json:"color" gorm:"default:0"`
	PartnerShare           bool           `json:"partner_share" gorm:"default:false"`
	//AccessToken            string         `json:"access_token"`
	FullName        string         `json:"full_name"`      //姓名
	SFZ             string         `json:"sfz"`            //身份证
	Identification  string         `json:"identification"` //认证意向
	Weixin          string         `json:"weixin"`         //微信
	QQ              string         `json:"qq"`
	Vat             string         `json:"vat"`              //统一社会信用代码
	Website         sql.NullString `json:"website"`          //网站
	Comment         string         `json:"comment"`          //公司简介
	IsConfirm       bool           `json:"is_confirm"`       //是否认证
	PendingApproval bool           `json:"pending_approval"` //等待审批
	TeamId          int64          `json:"team_id" gorm:"default:1"`
	//IsVip           bool           `json:"is_vip"`
	LoginId     int64 `json:"login_id"`
	Country     ResCountry
	State       ResCountryState
	City        ResCity
	UserIds     []ResUsers           `gorm:"foreignKey:PartnerId" json:"user_ids"`
	CategoryIds []ResPartnerCategory `json:"category_ids" gorm:"many2many:res_partner_res_partner_category_rel;References:Id"`
}

type ResGroupsUsersRel struct {
	Gid int64 `json:"gid"`
	Uid int64 `json:"uid"`
}

type ResCompanyUsersRel struct {
	Cid     int64      `json:"cid"`
	Company ResCompany `gorm:"foreignKey:Cid"`
	UserId  int64      `json:"user_id"`
}

type ResPartnerCategory struct {
	ResCommon
	Name string `json:"name"`
	//PartnerIds []*ResPartner `json:"partner_ids" gorm:"many2many:res_partner_res_partner_category_rel"`
}

type ResPartnerResPartnerCategoryRel struct {
	CategoryId int64 `json:"category_id"`
	PartnerId  int64 `json:"partner_id"`
}

type ResCountry struct {
	ResCommon
	Name string `json:"name"`
}

type ResPartnerTitle struct {
	ResCommon
	Name string `json:"name"`
}

type ResPartnerBank struct {
	ResCommon
	PartnerId          int64
	BankId             int64
	Bank               ResBank
	CompanyId          int64
	AccNumber          string
	SanitizedAccNumber string
	AllowOutPayment    bool
	Active             bool
}

type ResBank struct {
	ResCommon
	State   int64
	Country int64
	City    int64
	Name    string
	Street  string
	Street2 string
	Zip     string
	Email   string
	Phone   string
	Bic     string
	Active  bool
}
